package com.alliky.user.ui.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;

import com.alliky.core.base.viewmodel.ToolbarViewModel;
import com.alliky.core.binding.command.BindingCommand;
import com.alliky.core.bus.RxMessager;
import com.alliky.core.bus.SingleLiveEvent;
import com.alliky.core.data.DataRepository;
import com.alliky.core.global.Global;
import com.alliky.core.util.RxToast;
import com.alliky.core.widget.RxDialog;

/**
 * ================================================
 *
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2022/8/2 15:09
 * ================================================
 */
public class SettingViewModel extends ToolbarViewModel<DataRepository> {

    public SettingViewModel(@NonNull Application application) {
        super(application);
    }

    public void initToolbar() {
        setTitleText("设置");
    }

    public BindingCommand onClick = new BindingCommand(() -> {
        new RxDialog.Builder(getContext())
                .whitTitle("温馨提示")
                .whitContent("是否退出登录？")
                .setPositiveListener(dialog -> {
                    Global.UserManage.clearUser();
                    RxMessager.getDefault().send("退出登录", MyViewModel.KEY_LOGOUT);
                    finish();
                    dialog.dismiss();
                })
                .build()
                .show();

//        com.alliky.core.util.RxDialog dialog = new com.alliky.core.util.RxDialog.Builder<DialogCommonLayoutBinding>()
//                .layoutId(R.layout.dialog_common_layout)
//                .width(WindowManager.LayoutParams.WRAP_CONTENT)
//                .height(WindowManager.LayoutParams.WRAP_CONTENT)
//                .intercept((RxDialog.GeneralDialogEvent<DialogCommonLayoutBinding>) mBinding -> {
//                    mBinding.tvTitle.setText("温馨提示");
//                    mBinding.tvContent.setText("是否退出登录？");
//                })
//                .addClickViews(R.id.tv_cancel, R.id.tv_confirm)
//                .callbackClickOn((dialog1, v) -> {
//                    if (v.getId() == R.id.tv_confirm) {
//                        Global.UserManage.clearUser();
//                        RxMessager.getDefault().send("退出登录", MyViewModel.KEY_LOGOUT);
//                        finish();
//                        dialog1.dismiss();
//                    } else if (v.getId() == R.id.tv_cancel) {
//                        dialog1.dismiss();
//                    }
//
//                })
//                .Build(getContext());
//        dialog.show();
    });

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    private void call() {
        RxToast.normal("退出登录");
        uc.logout.call();
    }

    public class UIChangeObservable {
        //下拉刷新完成
        public SingleLiveEvent finishRefresh = new SingleLiveEvent<>();
        //上拉加载完成
        public SingleLiveEvent finishLoadMore = new SingleLiveEvent<>();

        public SingleLiveEvent logout = new SingleLiveEvent<>();
    }

}
